// packageA/pages/DisSettings/index.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        distributeEnabled: true,
        levels: [
          { name: '一级分销', value: '1', checked: true },
          { name: '二级分销', value: '2', checked: false }
        ],
        modes: [
          { name: '人人分销', value: 'everyone', checked: true },
          { name: '指定分销', value: 'assign', checked: false },
          { name: '满额分销', value: 'amount', checked: false }
        ],
        userTypes: [
          { name: '所有用户', value: 'all', checked: true },
          { name: '新用户', value: 'new', checked: false }
        ],
        bindModes: [
          { name: '永久', value: 'forever', checked: true },
          { name: '有效期', value: 'period', checked: false },
          { name: '临时', value: 'temporary', checked: false }
        ],
        calcModes: [
          { name: '商品售价', value: 'price', checked: true },
          { name: '实付金额', value: 'paid', checked: false },
          { name: '商品利润', value: 'profit', checked: false }
        ],
        withdrawModes: [
          { name: '手动转账', value: 'manual', checked: true },
          { name: '自动提现', value: 'auto', checked: false }
        ],
        firstLevelRate: '5',
        secondLevelRate: '3',
        promotionEnabled: true,
        withdrawFee: '0',
        posters: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },
    onDistributeEnableChange: function(e) {
        this.setData({
          distributeEnabled: e.detail.value
        });
      },
    
      onLevelChange: function(e) {
        const value = e.detail.value;
        const levels = this.data.levels.map(item => {
          item.checked = item.value === value;
          return item;
        });
        this.setData({ levels });
      },
    
      onModeChange: function(e) {
        const value = e.detail.value;
        const modes = this.data.modes.map(item => {
          item.checked = item.value === value;
          return item;
        });
        this.setData({ modes });
      },
    
      onUserTypeChange: function(e) {
        const value = e.detail.value;
        const userTypes = this.data.userTypes.map(item => {
          item.checked = item.value === value;
          return item;
        });
        this.setData({ userTypes });
      },
    
      onBindModeChange: function(e) {
        const value = e.detail.value;
        const bindModes = this.data.bindModes.map(item => {
          item.checked = item.value === value;
          return item;
        });
        this.setData({ bindModes });
      },
    
      onCalcModeChange: function(e) {
        const value = e.detail.value;
        const calcModes = this.data.calcModes.map(item => {
          item.checked = item.value === value;
          return item;
        });
        this.setData({ calcModes });
      },
    
      onWithdrawModeChange: function(e) {
        const value = e.detail.value;
        const withdrawModes = this.data.withdrawModes.map(item => {
          item.checked = item.value === value;
          return item;
        });
        this.setData({ withdrawModes });
      },
    
      onFirstLevelRateChange: function(e) {
        this.setData({
          firstLevelRate: e.detail.value
        });
      },
    
      onSecondLevelRateChange: function(e) {
        this.setData({
          secondLevelRate: e.detail.value
        });
      },
    
      onPromotionEnableChange: function(e) {
        this.setData({
          promotionEnabled: e.detail.value
        });
      },
    
      onWithdrawFeeChange: function(e) {
        this.setData({
          withdrawFee: e.detail.value
        });
      },
    
      chooseImage: function() {
        const that = this;
        wx.chooseImage({
          count: 5 - that.data.posters.length,
          sizeType: ['compressed'],
          sourceType: ['album', 'camera'],
          success: function(res) {
            const tempFilePaths = res.tempFilePaths;
            that.setData({
              posters: that.data.posters.concat(tempFilePaths)
            });
          }
        });
      },
    
      removeImage: function(e) {
        const index = e.currentTarget.dataset.index;
        const posters = this.data.posters;
        posters.splice(index, 1);
        this.setData({ posters });
      },
    
      onSave: function() {
        wx.showToast({
          title: '保存成功',
          icon: 'success',
          duration: 2000
        });
      },
    
      onCancel: function() {
        wx.navigateBack();
      },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})